/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.fjs.liyq.entity;

import java.io.Serializable;

/**
 * 购物车条目
 * @author danny
 */
public class CartItem implements Serializable {
    
    private Product product;
    private int quantity;

    @Override
    public boolean equals(Object obj) {
        CartItem co = (CartItem) obj;
        if (obj == null || co.getProduct() == null) {
            return false;
        } else {
            return product.getEpId().equals(co.getProduct().getEpId());
        }
    }

    /**
     * @return the product
     */
    public Product getProduct() {
        return product;
    }

    /**
     * @param product the product to set
     */
    public void setProduct(Product product) {
        this.product = product;
    }

    /**
     * @return the quantity
     */
    public int getQuantity() {
        return quantity;
    }

    /**
     * @param quantity the quantity to set
     */
    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    /**
     * @return the cost
     */
    public double getCost() {
        return product.getEpPrice() * quantity;
    }

    public void add(int num) {
        quantity += num;
    }
    
    public void sub(int num) {
        quantity -= num;
    }
}
